/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/
function Uri (str, strictMode) {
	var	o = Uri.options,
		m = o.parser[strictMode ? "strict" : "loose"].exec(str),
		i = 14;

	while (i--) 
		this[o.key[i]] = (function (i) { return function() { return m[i]; } })(i)
	;
};

Uri.options = {
	key: ["source","schema","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	},
	q:   {
		parser: /(?:^|[&])([^&=]*)(=?)([^&]*)/g
	}
};

Uri.prototype.queryHash = function () {
	var	o    = Uri.options,
		hash = {};
	if (this[o.key[12]]()) this[o.key[12]]().replace(o.q.parser, function ($0, $1, $2, $3) {
		if ($1) hash[decodeURIComponent($1)] = $2 ?  decodeURIComponent($3) : true;
	});

	return hash;
}

function jUri(str) { return new Uri(str); }

String.prototype.parseUri       = function () { return new Uri(this.valueOf()); }
String.prototype.parseUriStrict = function () { return new Uri(this.valueOf(), true); }

